/*
 * ImageLog.h
 *
 *  Created on: May 10, 2010
 *      Author: Soheil Damangir
 */

#ifndef IMAGELOG_H_
#define IMAGELOG_H_
#include <iostream>
#include <string>
#include "printfstring.h"
#include "image.h"
using namespace kthrobot;
using std::string;
namespace Group5 {

class ImageLog {
  int count;
  Image image;
  ImageLog(): count(0),image(1){};
  ImageLog(const ImageLog&);
public:
  static ImageLog&get()
  {
    static ImageLog instance;
    return instance;
  }
  void imageReport()
  {
    std::cout << image.w() << "\t" << image.h() << "\t" << image.num_components() << endl;
  }

  void Log(Image*image, const char* pref="log_")
  {
    string file_name = PrintFString("%s%07d.ppm", pref, count++);
    image->SavePPM(file_name);
  }
  void Log(uint8_t**arr,const int&w, const int&h, const char* pref="log_")
  {
    image.Prepare(w,h);
    uint8_t*b = image.buffer();
    for (int i=0;i<w;i++)
    {
      for (int j=0;j<h;j++)
      {
        b[i+j*w] = arr[j][i];
      }
    }
    Log(&image,pref);
  }
  void LogBinary(bool**arr,const int&w, const int&h,const char* pref="log_")
  {
    image.Prepare(w,h);
    uint8_t*b = image.buffer();
    for (int i=0;i<w;i++)
    {
      for (int j=0;j<h;j++)
      {
        b[i+j*w] = 255*arr[j][i];
      }
    }
    Log(&image, pref);
  }
  virtual ~ImageLog(){}
};

}

#endif /* IMAGELOG_H_ */
